<template>
  <div class="app-container">
    <el-form ref="elFormSetting" :model="formSettingData" :rules="rules" size="medium" label-width="120px">

      <el-form-item label="原密码" prop="old_password">
        <el-input
          v-model="formSettingData.old_password"
          placeholder="原密码"
          clearable
          :style="{width:'50%'}"
        />
      </el-form-item>
      <el-form-item label="新密码" prop="new_password">
        <el-input
          v-model="formSettingData.new_password"
          placeholder="新密码"
          clearable
          :style="{width:'50%'}"
        />
      </el-form-item>
      <el-form-item label="重复新密码" prop="dbl_new_password">
        <el-input
          v-model="formSettingData.dbl_new_password"
          placeholder="新密码"
          clearable
          :style="{width:'50%'}"
        />
      </el-form-item>

      <el-form-item size="large">
        <el-button type="primary" :loading="loading" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'UserModifyPassword',
  components: {},
  props: [],
  data() {
    return {
      formSettingData: {
        old_password: undefined,
        new_password: undefined,
        dbl_new_password: undefined
      }
    }
  },
  methods: {
    submitForm() {
      this.$refs['elFormSetting'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('user/modifypass', this.formSettingData).then(() => {
            // this.$router.push({ path: this.redirect || '/' })
            this.loading = false
          }).catch((err) => {
            console.error(err)
            this.loading = false
          })
        } else {
          this.loading = false
        }
      })
    },
    resetForm() {
      this.$refs['elFormSetting'].resetFields()
    }
  }
}
</script>

